#ifndef REQUEST_H
#define REQUEST_H

#include <QMap>
#include <QNetworkRequest>
#include <QString>
#include <QUrl>
#include <QUrlQuery>
#include <QVariantMap>

class Request
{
public:
    Request();
    Request(QString url);;
    QUrl url();
    QUrl queryUrl();
    void addQuery(const QString &key, const QString &value);
    void setUrl(const QString &newUrl);
    void setData(const QString &data);
    void setData(const QVariantMap &data);
    void setData(QVariantList &data);
    QByteArray data();

    void setHeader(const QString &header, const QString &value);
    void setHeaders(const QMap<QString, QString> &newHeaders);
    QMap<QString, QString> headers() const;

    QVariantMap variantHeaders() const;
    void setVariantHeaders(const QVariantMap &newVariantHeaders);

    int timeout() const;
    void setTimeout(int timeout);
    
    QString timeoutMessage() const;
    void setTimeoutMessage(const QString &newTimeoutMessage);

    void requestParserHeaders(QNetworkRequest &request)
    {
        if (m_headers.isEmpty() == false)
        {
            foreach (auto var, m_headers.keys())
            {
                request.setRawHeader(var.toUtf8(), m_headers.value(var).toUtf8());
            }

        }
        if (m_variantHeaders.isEmpty() == false)
        {
            foreach (auto var, m_variantHeaders.keys())
            {
                request.setRawHeader(var.toUtf8(), m_variantHeaders.value(var).toString().toUtf8());
            }
        }
    }

private:
    QString m_url;

    QMap<QString, QString> m_headers;
    QVariantMap m_variantHeaders;
    
    QString m_data;
    QUrlQuery m_query;
    
    int m_timeout;
    QString m_timeoutMessage;
};

#endif // REQUEST_H
